<?php

include_once("core/controller.php");
include_once("core/libs/configFile.php");
include_once("core/versionHandler.php");
/**
 * This Controller is used to activate/desactivate maintenance in multiple actions
 * @copyright inovia
 * @package oolime_manager
 *
 */
class editMaintenanceAll extends Controller {
   
	// only for manager group
	function isLegitimate(){
		global $configDispatcher;
		
    // Inputs verifications
    if(!$this->request->exist(Array("maintenance"))){
      $this->response->addError("No maintenance state","maintenance");
      return false;
    }else if(!$this->request->exist(Array("actionM"))){
      $this->response->addError("No action selected","actionM");
      return false;
    }else {
  	  if(!( $this->request->get('maintenance')=='enable' || $this->request->get('maintenance')=='disable') ){
        $this->response->addError("Error in the maintenance action","maintenance");
        return false; 
      }
    }
    foreach($this->request->get('actionM') as $a => $val){
      if(!isset($configDispatcher[$a])){
        $this->response->addError("Action ".$a." does not exist","actionM");
        return false;
      }
    }
    return true;
	}

	function actions(){
		global $configDispatcher;
		$conf = new ConfigFile('actions.php');

    
    foreach($this->request->get('actionM') as $key => $val){
      if($this->request->get('maintenance') == "enable"){
        $value = 1;
      }else{
        $value = 0;
      }
  	  $configDispatcher[$key][3] = $value;
    }

    if(! $conf->setVar("\$configDispatcher",$configDispatcher,true)){
      $this->response->addError('Maintenance state failed','actionM');
    }



		/* Launch homeMaintenance*/
		include('controls/manager/homeMaintenance.php');
		$this->response->setXSLT('views/manager/homeMaintenance.xsl');
		new HomeMaintenance();
  }

	function defaultActions(){
		include('controls/manager/homeMaintenance.php');
		$this->response->setXSLT('views/manager/homeMaintenance.xsl');
		new HomeMaintenance();
  }
}



?>
